home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Online / SpeakFreely / src / lpc10 / random.c < prev    next >
Text File  |  2000-05-18  |  952b  |  45 lines

  1. /***********************************************************************
  2. *
  3. *    RANDOM Version 49
  4. *
  5. ***********************************************************************
  6. *
  7. *  Pseudo random number generator based on Knuth, Vol 2, p. 27.
  8. *
  9. * Function Return:
  10. *  RANDOM - Integer variable, uniformly distributed over -32768 to 32767
  11. *
  12. * Warning:  This routine contains statements which are specific to VAX Fortran.
  13. *        I'll try it anyway - Tiner
  14. */
  15.  
  16. #define MIDTAP 1
  17. #define MAXTAP 4
  18.  
  19. int Rrandom ()
  20. {
  21. int the_random;
  22. static short y[MAXTAP+1]={-21161, -8478, 30892,-10216, 16950};
  23. static int j=MIDTAP, k=MAXTAP;
  24.  
  25. /*   The following is a 16 bit 2's complement addition,
  26. *   with overflow checking disabled    */
  27.  
  28. y[k] += y[j];
  29.  
  30. if(y[k] > 32767) /* to make 16 bit rollover to -/+ */
  31.   y[k] = -(32768 - (y[k] & 32767));
  32. if(y[k] < -32768)
  33.   y[k] = y[k] & 32767;
  34.     
  35. the_random = y[k];
  36. k--;
  37. if (k < 0) k = MAXTAP;
  38. j--;
  39. if (j < 0) j = MAXTAP;
  40.  
  41. return(the_random);
  42.  
  43. }
  44.  
  45.